package cn.monkey.family.data;

import org.mapstruct.Named;

import javax.inject.Inject;

public abstract class EntityMapper<D, T extends Entity, V extends EntityVo> implements DataMapper<D, T, V> {

    @Inject
    UserSelector userSelector;

    @Named("getUserIdAndNamePairFromId")
    public KVPair<String, String> getUserIdAndNamePairFromId(String id) {
        return this.userSelector.findById(id).map(u -> KVPair.of(u.getId(), u.getNickName())).orElse(null);
    }

    @Override
    public abstract T toEntity(D d);

    @Override
    public abstract V toVo(T t);
}
